package com.zookeeper8022.curatorzkclient;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.data.Stat;

/**
 * @author liyanhao
 * @Date 2023-02-17 19:22
 */
public class CuratorDemo {
    private final static String CLUSTER_CONNECT_STR
            = "192.168.139.30:2191,192.168.139.30:2192,192.168.139.30:2193";

    public static void main(String[] args) throws Exception {
        //构建客户端实例
        CuratorFramework curatorFramework = CuratorFrameworkFactory.builder().connectString(CLUSTER_CONNECT_STR)
                .sessionTimeoutMs(4000)
                .retryPolicy(new ExponentialBackoffRetry(1000, 3))
                .namespace("")
                .build();
        //启动客户端
        curatorFramework.start();
        Stat stat = new Stat();
        //查询节点信息
        byte[] bytes = curatorFramework.getData().storingStatIn(stat)
                .forPath("/user");
        System.out.println(new String(bytes));
        curatorFramework.close();
    }

}
